<?php

namespace App\Models\Orm;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;

class UserCoinLog extends Model
{
    const TABLE_NAME = 'user_coin_log';
    const PRIMARY_KEY = 'id';

    protected $table = self::TABLE_NAME;
    //主键id
    protected $primaryKey = self::PRIMARY_KEY;
    //查询字段
    protected $visible = [];
    //加黑名单
    protected $guarded = [];
    // 上线状态
    // 动作
    const ACTION_WITHDRAW = 1;          // 提现
    const ACTION_INVITE = 2;            // 邀请
    const ACTION_ACTIVITY = 3;          // 活动
    const ACTION_EXCHANGE = 4;          // 积分兑换


    // 动作描述
    public static $action_text = [
        self::ACTION_WITHDRAW => '提现申请',
        self::ACTION_INVITE => '邀请赠送',
        self::ACTION_ACTIVITY => '活动赠送',
        self::ACTION_EXCHANGE => '积分兑换',

    ];

    // 获取动作关联记录方法名,必须在本类中定义该方法
    public static $action_function_names = [
        self::ACTION_WITHDRAW => 'getWithdraw',
        self::ACTION_INVITE => 'getInvite',
        self::ACTION_ACTIVITY => 'getActivity',
        self::ACTION_EXCHANGE => 'getExchange',

    ];
    // 类型
    const TYPE_ADD = 0;                 // 增加
    const TYPE_CUT = 1;                 // 减少

    // 类型描述
    public static $type_text = [
        self::TYPE_ADD => '增加',
        self::TYPE_CUT => '减少',
    ];

    // 状态
    const STATUS_INIT = 1;              // 发起
    const STATUS_ACCESS = 2;            // 成功
    const STATUS_FAILED = 3;            // 驳回


    // 状态描述
    public static $status_text = [
        self::STATUS_INIT => '处理中',
        self::STATUS_ACCESS => '放款',
        self::STATUS_FAILED => '驳回',
    ];



    /**
     * 获取当前记录动作描述
     * @param $action
     * @return string
     */
    public static function getActionText($action)
    {
        return self::$action_text[$action] ?: '';
    }

    /*
     * 获取提现的记录
     */
    public  function getWithDraw()
    {
        return $this->hasOne(AwUserWithdraw::class, 'id', 'order_id')->getResults();

    }

    /**
     * 获取当前记录动作描述
     * @param $action
     * @return string
     */
    public static function getStatusText($action)
    {
        return self::$status_text[$action] ?: '';
    }

}